package service

import (
	v1 "open/api/open/service/v1"
	"open/internal/dao"
	"open/internal/model/event/topic"
	"open/internal/service/admin"
	"open/internal/service/notify"

	"github.com/google/wire"
)

// ProviderSet is service providers.
var ProviderSet = wire.NewSet(NewService, admin.NewService, notify.NewService)

// Service 服务
type Service struct {
	v1.UnimplementedOpenServiceServer

	dao *dao.Dao
}

// NewService 新建服务
func NewService(dao *dao.Dao) *Service {
	s := &Service{dao: dao}

	s.runWorker(topic.TaskSyncQRCode, s.HandleTaskSyncQRCode)
	s.runWorker(topic.TaskCommitCode, s.HandleTaskCommitCode)
	s.runWorker(topic.TaskCommitAudit, s.HandleTaskCommitAudit)
	s.runWorker(topic.TaskUpdateStatus, s.HandleTaskUpdateStatus)
	s.runWorker(topic.TaskRelease, s.HandleTaskRelease)
	s.runWorker(topic.TaskSendWechatPubMessage, s.HandleTaskSendWechatPubMessage)
	s.runWorker(topic.TaskSyncWechatPubTemplate, s.HandleTaskSyncWechatPubTemplate)

	return s
}
